{php include wl_template('common/header');}
<ul class="nav nav-tabs">
	<li ><a href="{php echo web_url('paidpromotion/payactive/activelist')}">活动列表</a></li>
	<li {if empty($id)}class="active"{/if}><a href="{php echo web_url('paidpromotion/payactive/createactive')}">添加活动</a></li>
	{if !empty($id)}
	<li class="active"><a href="#">编辑活动</a></li>
	{/if}
</ul>
<div class="app-content">
	<div class="app-form">
		<form action="" method="post" class="form-horizontal form form-validate" id="form">
		<div class="panel panel-default">
		<div class="panel-heading">活动设置</div>
		<div class="panel-body">
			<div class="form-group">
				<label class="col-sm-2 control-label">活动标题</label>
				<div class="col-sm-7 col-xs-12">
					<input type="text" name="active[title]" class="form-control" value="{$active['title']}" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">活动广告图</label>
				<div class="col-sm-6 col-xs-6">
					{php echo attachment_select('active[img]',$active['img']);}
					<span class='help-block'>推荐图片比例640*300,实际比例按照后台基础设置比例显示。</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">广告链接</label>
				<div class="col-sm-9">
					<div class="input-group" style="margin: 0;">
						<input type="text" name="active[advurl]" class="form-control" value="{$active['advurl']}" readonly="readonly" placeholder="" id="advlink">
						<span data-input="#advlink" data-toggle="selectUrl" class="input-group-addon btn btn-default">选择链接</span>
						<span class="input-group-addon btn btn-default clearinput">X</span>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">参与用户资格</label>
				<div class="col-sm-9">
					<label class="radio-inline">
                        <input type="radio" value="0" name="active[userstatus]" {if $active['userstatus'] == 0 || empty($active['userstatus']) } checked {/if}>全体用户
                    </label>
					<label class="radio-inline">
                        <input type="radio" value="1" name="active[userstatus]" {if $active['userstatus'] == 1} checked {/if}>一卡通会员
                    </label>
				</div>
			</div>
			<div class="form-group" id="orderprice" >
				<label class="col-sm-2 control-label">要求订单金额</label>
				<div class="col-sm-9">
					<div class="input-group">
						<span class="input-group-addon">￥</span>
						<input type="number" name="active[orderprice]" class="form-control" value="{$active['orderprice']}" />
					</div>
					<span class='help-block'>不填写或填0即不要求订单金额超过多少才赠送礼品。</span>
				</div>
			</div>

			<div class="form-group" >
				<label class="col-sm-2 control-label">要求支付方式</label>
				<div class="col-sm-9">
					<label class="checkbox-inline">
						<input type="checkbox" value="1" {if in_array(1,$active['paytypearray'])} checked {/if}  name="paytype[]" />余额
					</label>
					<label class="checkbox-inline">
						<input type="checkbox" value="2" {if in_array(2,$active['paytypearray'])} checked {/if}  name="paytype[]" />微信支付
					</label>
					<label class="checkbox-inline">
						<input type="checkbox" value="3" {if in_array(3,$active['paytypearray'])} checked {/if}  name="paytype[]" />支付宝
					</label>
					<label class="checkbox-inline">
						<input type="checkbox" value="6" {if in_array(6,$active['paytypearray'])} checked {/if}  name="paytype[]" />0元购
					</label>
					<span class="help-block">设置后只有指定支付方式会赠送礼品,不勾选即所有支付方式可用。</span>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">赠送积分</label>
				<div class="col-sm-9">
					<div class="input-group">
						<span class="input-group-addon">每消费</span>
						<input type="number" name="active[integralrate]" class="form-control" value="{$active['integralrate']}" />
						<span class="input-group-addon">元赠送</span>
						<input type="number" name="active[integral]" class="form-control" value="{$active['integral']}" />
						<span class="input-group-addon">积分</span>
					</div>
					<span class='help-block'>金额不填或填0即为不赠送积分,金额和积分最多保存两位小数,计算结果按比例保留两位小数。</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">赠送余额</label>
				<div class="col-sm-9">
					<div class="input-group">
						<span class="input-group-addon">每消费</span>
						<input type="number" name="active[balancerate]" class="form-control" value="{$active['balancerate']}" />
						<span class="input-group-addon">元赠送</span>
						<input type="number" name="active[balance]" class="form-control" value="{$active['balance']}" />
						<span class="input-group-addon">余额</span>
					</div>
					<span class='help-block'>金额不填或填0即为不赠送余额,金额和余额最多保存两位小数,计算结果按比例保留两位小数。</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">计算方式</label>
				<div class="col-sm-9">
					<label class="radio-inline">
						<input type="radio" value="0" name="active[ratestatus]" {if $active['ratestatus'] == 0 || empty($active['ratestatus']) } checked {/if}>按比例
					</label>
					<label class="radio-inline">
						<input type="radio" value="1" name="active[ratestatus]" {if $active['ratestatus'] == 1} checked {/if}>按阶梯
					</label>
					<span class='help-block'>赠送的积分余额计算方式，例：每5元赠送10积分，当用户支付13元时，按比例计算会赠送26积分，按阶梯计算会赠送20积分。</span>

				</div>
			</div>


			<div class="form-group">
				<label class="col-sm-2 control-label">赠品</label>
				<div class="col-sm-9">
					<label class="radio-inline" onclick="changegiftstatus(0)" >
                        <input type="radio" value="0" name="active[giftstatus]" {if $active['giftstatus'] == 0 || empty($active['giftstatus'])} checked {/if}>无赠品
                    </label>
					{if p('wlcoupon')}
					<label class="radio-inline" onclick="changegiftstatus(1)" >
                        <input type="radio" value="1" name="active[giftstatus]" {if $active['giftstatus'] == 1} checked {/if}>超级券
                    </label>
					{/if}
					{if p('halfcard')}
					<label class="radio-inline" onclick="changegiftstatus(2)" >
                        <input type="radio" value="2" name="active[giftstatus]" {if $active['giftstatus'] == 2} checked {/if}>激活码
                    </label>
					{/if}
					{if p('redpack')}
					<label class="radio-inline" onclick="changegiftstatus(3)" >
						<input type="radio" value="3" name="active[giftstatus]" {if $active['giftstatus'] == 3} checked {/if}>在线红包
					</label>
					{/if}
				</div>
			</div>
			<!--赠券-->
			<div class="form-group" id="giftcoupon"  {if $active['giftstatus'] != 1} style="display: none;" {/if}>
				<label class="col-xs-7 col-sm-3 col-md-2 control-label">赠送超级券</label>
				<div class="col-sm-7 col-xs-6">
					<select name="active[giftcouponid][]"  multiple="multiple"  class="form-control select2 col-sm-7 col-xs-6" style="width: 100%;">
						{if $giftcoupons}
                            {loop $giftcoupons $gift}
                                <option value="{$gift['id']}" {if in_array($gift['id'],$active['giftcouponid'])} selected="selected" {/if}>{$gift['title']}</option>
                            {/loop}
						{else}
							<option value="0"  selected="selected" >无可用卡券</option>
						{/if}
					</select>
					<span class='help-block'>请不要一次赠送过多卡券，可能导致漏赠或不赠。</span>
				</div>
			</div>
			<!--赠码-->
			<div class="form-group" id="giftcode"  {if $active['giftstatus'] != 2} style="display: none;" {/if}>
				<label class="col-sm-2 control-label">赠送激活码</label>
				<div class="col-sm-7 col-xs-6">
					<select name="active[codereamrk]" class="form-control select2 col-sm-7 col-xs-6" style="width: 100%;">
						{if $giftcode}
						{loop $giftcode $codee}
						<option value="{$codee['remark']}" {if $codee['remark'] == $active['codereamrk']} selected="selected" {/if}>{$codee['remark']}</option>
						{/loop}
						{else}
							<option value="0"  selected="selected" >无可用激活码</option>
						{/if}
					</select>
				</div>
			</div>
			<!--赠送红包-->
			<div class="form-group" id="giftredpack"  {if $active['giftstatus'] != 3} style="display: none;" {/if}>
				<label class="col-xs-7 col-sm-3 col-md-2 control-label">赠送红包</label>
				<div class="col-sm-7 col-xs-6">
					<select name="active[giftredpack][]"  multiple="multiple"  class="form-control select2 col-sm-7 col-xs-6" style="width: 100%;">
						{if $giftredlist}
						{loop $giftredlist $red}
						<option value="{$red['id']}" {if in_array($red['id'],$active['giftredpack'])} selected="selected" {/if}>{$red['title']}</option>
						{/loop}
						{else}
						<option value="0"  selected="selected" >无可用红包</option>
						{/if}
					</select>
					<span class='help-block'>请不要一次赠送过多红包，可能导致漏赠或不赠。</span>
				</div>
			</div>
			<!--获取方式-->
			<div class="form-group" id="getstatus" {if $active['giftstatus'] != 1} style="display: none;" {/if}>
				<label class="col-sm-2 control-label">发放方式</label>
				<div class="col-sm-9">
					<label class="radio-inline" >
                        <input type="radio" value="0" name="active[getstatus]" {if $active['getstatus'] == 0 || empty($active['getstatus'])} checked {/if}>手动领取
                    </label>
                    <label class="radio-inline" >
                        <input type="radio" value="1" name="active[getstatus]" {if $active['getstatus'] == 1} checked {/if}>自动发放
                    </label>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-2 control-label">赠送会员</label>
				<div class="col-sm-9">
					<div class="input-group data-item" style="margin-top: 10px;">
						<span class="input-group-addon">会员等级</span>
						<select name="active[cardlevelid]"  class="form-control chosen-select">
							<option value="0">{$_W['wlsetting']['halflevel']['name']}</option>
							{loop $levellist $v}
							<option value="{$v['id']}" {if $active['cardlevelid'] == $v['id']}selected{/if}>{$v['name']}</option>
							{/loop}
						</select>
						<span class="input-group-addon">时间</span>
						<input type="number" name="active[cardday]" class="form-control" value="{$active['cardday']}">
						<span class="input-group-addon">天</span>
						<span onclick="removes(this)" class="input-group-addon btn btn-default data-item-delete"><i class="fa fa-remove"></i> 删除</span>
					</div>
					<span class='help-block'>如果用户已经是此等级会员,会增加会员时长;如果用户已经是会员且不是此等级则不会赠送会员。</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">成为分销商</label>
				<div class="col-sm-9">
					<select name="active[dislevelid]"  class="form-control chosen-select">
						<option value="0">不赠送分销商资格</option>
						{loop $dislist $dis}
						<option value="{$dis['id']}" {if $active['dislevelid'] == $dis['id']}selected{/if}>{$dis['name']}</option>
						{/loop}
					</select>
					<span class='help-block'>如果用户已经是分销商，分销商等级低于此等级，会提升用户分销商等级；如果用户分销商等级高于此等级，则不会变化。</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">赠送时间</label>
				<div class="col-sm-9">
					<label class="radio-inline" >
						<input type="radio" value="0" name="active[timetype]" {if $active['timetype'] == 0 || empty($active['timetype'])} checked {/if}>订单支付时
					</label>
					<label class="radio-inline" >
						<input type="radio" value="1" name="active[timetype]" {if $active['timetype'] == 1} checked {/if}>订单完成时
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">状态</label>
				<div class="col-sm-9">
					<label class="radio-inline" >
                        <input type="radio" value="1" name="active[status]" {if $active['status'] == 1} checked {/if}>启用
                    </label>
					<label class="radio-inline" >
                        <input type="radio" value="0" name="active[status]" {if $active['status'] == 0 || empty($active['status'])} checked {/if}>禁止
                    </label>
				</div>
			</div>
		</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label"></label>
			<div class="col-sm-9">
				<input type="hidden" name="id" value="{$id}" id="id"/>
				<input type="submit" name="submit" value="提交" class="btn btn-primary min-width" />
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
		</form>
	</div>
</div>
<script>
	// function changeorderstatus(flag){
	// 	if(flag){
	// 		$('#orderprice').hide();
	// 		$('#ordergoods').show();
	// 	}else{
	// 		$('#orderprice').show();
	// 		$('#ordergoods').hide();
	// 	}
	// 	showplu();
	// }

	$(".form").on('click','.clearinput',function () {
		$(this).prev().prev().val('');
	});

	function changegiftstatus(flag){
		if(flag == 1){
			$('#giftcoupon').show();
			$('#giftcode').hide();
			$('#getstatus').show();
			$('#giftredpack').hide();
		}else if(flag == 2){
			$('#giftcoupon').hide();
			$('#giftcode').show();
			$('#getstatus').hide();
			$('#giftredpack').hide();
		}else if(flag == 3){
			$('#giftcoupon').hide();
			$('#giftcode').hide();
			$('#getstatus').hide();
			$('#giftredpack').show();
		}else{
			$('#giftcoupon').hide();
			$('#giftcode').hide();
			$('#getstatus').hide();
			$('#giftredpack').hide();
		}
	}
	// $(function(){
	// 	var t = setInterval(de,1000);
	// 	function de(){
	// 		$('.layui-form-select').remove();
	// 	}
	// 	showplu();
	// });
	//
	// function showplu(){
	// 	var arrChk=$("input[name='plugin[]']:checked");
	// 	var arrplu = new Array();
	// 	$(arrChk).each(function(){
	// 		arrplu.push($(this).val());
	// 	});
	// 	if($.inArray('rush',arrplu) > -1){
	// 		$('#rushgoods').show();
	// 	}else{
	// 		$('#rushgoods').hide();
	// 	}
	// 	if($.inArray('groupon',arrplu) > -1){
	// 		$('#groupongoods').show();
	// 	}else{
	// 		$('#groupongoods').hide();
	// 	}
	// 	if($.inArray('fightgroup',arrplu) > -1){
	// 		$('#fightgroupgoods').show();
	// 	}else{
	// 		$('#fightgroupgoods').hide();
	// 	}
	// 	if($.inArray('coupon',arrplu) > -1){
	// 		$('#coupongoods').show();
	// 	}else{
	// 		$('#coupongoods').hide();
	// 	}
	// 	if($.inArray('halfcard',arrplu) > -1){
	// 		$('#halfcardgoods').show();
	// 	}else{
	// 		$('#halfcardgoods').hide();
	// 	}
	// 	if($.inArray('charge',arrplu) > -1){
	// 		$('#chargegoods').show();
	// 	}else{
	// 		$('#chargegoods').hide();
	// 	}
	// }
</script>
{php include wl_template('common/footer');}